/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.mycompany.test;

import org.dom4j.io.SAXReader;
import org.dom4j.Document;
import org.dom4j.Element;

import java.net.URL;
import java.net.Authenticator;
import java.net.MalformedURLException;
import java.net.PasswordAuthentication;
import java.util.List;
import org.dom4j.DocumentException;
/**
 *
 * @author vovy1114
 */
public class JenkinsInfo {

    public static void main(String[] args) throws MalformedURLException, DocumentException {
        URL url = new URL("http://localhost:8080/api/xml");

        // if you are calling security-enabled Hudson and
        // need to invoke operations and APIs that are protected,
        // consult the 'SecuredMain" class
        // in this package for an example using HttpClient.
        // read it into DOM.
        Document dom = new SAXReader().read(url);

        // scan through the job list and print its status
        for (Element job : (List<Element>) dom.getRootElement().elements("job")) {
            System.out.println(String.format("Name:%s\tStatus:%s",
                    job.elementText("name"), job.elementText("color")));
        }
    }

}
